// pages/alarmDetail/alarmDetail.ts
import {getAlarmDetail,getEquipmentDetail,getAlarmDealHistary} from '../../api/site-monitoring'
import type{siteDetail,warnList} from '../../type/type'
import {JZecharts,RYecharts} from '../../api/echarts'
const dayjs = require('../../utils/day.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        type:"" as String,
        id:-1 as Number | String,
        list:[],
        tabsName:'1',
        historyList:[] as siteDetail[],
        alarmList:[] as warnList[],
        isImage:false as Boolean,
        imageUrl:'' as String,
        isError:false as Boolean,
        echarts1List:[] as string[],
        echarts2List:[] as string[],
        echarts3List:[] as string[],
        echarts4List:[] as string[],
        echarts5List:[] as string[],
        echarts6List:[] as string[],
        echarts7List:[] as string[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(option) {
      this.setData({
        type:option.type,
        id:option.id
    })
    },
    onClick(e:any){
      const {name} = e.detail
      this.setData({
        tabsName:name
      })
    },
    getEchartsInfo(type:string){
      const {id}  = this.data
      const time = dayjs().format('YYYY-MM-DD')
      const comID = wx.getStorageSync("userInfo").data.comID
      if(type=='2'){
        RYecharts(comID,id,time).then((res:any)=>{
          console.log(res)
          const echarts1 = [],echarts2 = [],echarts3 = [],echarts4 = [],echarts5 = [],echarts6 = [],echarts7 = [];
          echarts1.push(res.data.data.hours,res.data.data.总供温,res.data.data.总回温)
          echarts2.push(res.data.data.hours,res.data.data.总供压,res.data.data.总回压)
          echarts3.push(res.data.data.hours,res.data.data.总供累积热量,res.data.data.总回累积热量)
          echarts4.push(res.data.data.hours,res.data.data.总供累积流量,res.data.data.总回累积流量)
          // echarts5.push(res.data.data.补水流量表瞬时流量,res.data.data.补水流量表累计流量)
          echarts6.push(res.data.data.hours,res.data.data.总供瞬时流量,res.data.data.总回瞬时流量)
          echarts7.push(res.data.data.hours,res.data.data.总供瞬时热量,res.data.data.总回瞬时热量)
          // console.log(echarts6,echarts7)
          this.setData({
            echarts1List:echarts1,
            echarts2List:echarts2,
            echarts3List:echarts3,
            echarts4List:echarts4,
            // echarts5List:echarts5,
            echarts6List:echarts6,
            echarts7List:echarts7
          })
        })
      }else{
        JZecharts(comID,id,time).then((res:any)=>{
          console.log(res)
          const echarts1 = [],echarts2 = [],echarts3 = [],echarts4 = [],echarts5 = [],echarts6 = [],echarts7 = [];
          echarts1.push(res.data.data.hours,res.data.data.一次入温,res.data.data.一次回温,res.data.data.二次供温,res.data.data.二次回温)
          echarts2.push(res.data.data.hours,res.data.data.一次供压,res.data.data.一次回压,res.data.data.二次供压,res.data.data.二次回压)
          echarts3.push(res.data.data.hours,res.data.data.一次热表累积热量,res.data.data.二次热表累积热量)
          echarts4.push(res.data.data.hours,res.data.data.一次热表累积流量,res.data.data.二次热表累积流量)
          echarts5.push(res.data.data.hours,res.data.data.补水流量表瞬时流量,res.data.data.补水流量表累计流量)
          echarts6.push(res.data.data.hours,res.data.data.一次热表瞬时流量,res.data.data.二次热表瞬时流量)
          echarts7.push(res.data.data.hours,res.data.data.一次热表瞬时热量,res.data.data.二次热表瞬时热量)
          // console.log(echarts6,echarts7)
          this.setData({
            echarts1List:echarts1,
            echarts2List:echarts2,
            echarts3List:echarts3,
            echarts4List:echarts4,
            echarts5List:echarts5,
            echarts6List:echarts6,
            echarts7List:echarts7
          })
        })
      }
    },
    getList(){
        let type = this.data.type;
        let id = this.data.id;
        const comID = wx.getStorageSync("userInfo").data.comID
        getAlarmDetail(comID,type,id).then((res:any)=>{
            this.setData({
                alarmList:res.data.data
            })
            // console.log(this.data.alarmList)
        })
        getEquipmentDetail(comID,type,id).then((res:any)=>{
            this.setData({
                list:res.data.data
            })
            // console.log(res)
        })
        getAlarmDealHistary(comID,type,id).then((res:any)=>{
            this.setData({
                historyList:res.data.data
            })
            // console.log(res)
        })
    },
    onClickLeft(){
        wx.navigateBack({
            delta:1
        })
    },
    handleProcessor(e:any){
        wx.navigateTo({
            url:'/pages/alarmprocessor/alarmprocessor?type='+ this.data.type +'&id='+e.currentTarget.dataset.id
        })
    },
    handleImage(e:any){
        this.setData({
            imageUrl:e.currentTarget.dataset.imge,
            // imageUrl:'https://s3.bmp.ovh/imgs/2023/11/20/8f3ec8bf8fdb83e3.png',
            isImage:true,
        })
        // console.log(e)
    },
    onClose(){
        this.setData({
            isImage:false
        })
    },
    onImage(e:any){
        if(e){
            this.setData({
                isError:true
            })
        }else{
            this.setData({
                isError:false
            })
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
      const {type} = this.data
      
        this.getList();
        this.getEchartsInfo(type)
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})